#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

void process(vector<char>& nums , int index , vector<string>& ans)
{
  if (nums.size() == index)
  {
    string ans1;
    for (auto x : nums)
    {
      ans1 += x;
    }
    ans.push_back(ans1);
    return;
  }
  else 
  {
    vector<int> bol = {0};
    bol.resize(256);

    for (size_t i = index ; i < nums.size() ; i++)
    {
      if(!bol[nums[i]])
      {
         bol[nums[i]] = 1;
         swap(nums[i] , nums[index]);
         process(nums , index + 1 , ans);
         swap(nums[i] , nums[index]);
       }
    }
  }
}





int main()
{
  vector<char> nums = {'a' , 'c' , 'c'};
  vector<string> ans;
  process(nums , 0 , ans);

  for (auto x : ans )
  {
    cout << x << " "; 
  }

  cout << endl;
  return 0;
}
